Block< Type > Class Template Reference

#include <block.h>

List of all members.

Public Member Functions

 Block (int size, void(*err_function)(char *)=NULL)
 ~Block ()
Type * New (int num=1)
Type * ScanFirst ()
Type * ScanNext ()
void Reset ()

Private Types

typedef Block::block_st block

Private Attributes

int block_size
blockfirst
blocklast
blockscan_current_block
Type * scan_current_data
void(* error_function )(char *)

Classes

struct  block_st


Detailed Description

template<class Type>
class Block< Type >

Definition at line 99 of file block.h.


Member Typedef Documentation

template<class Type>
typedef struct Block::block_st Block< Type >::block [private]


Constructor & Destructor Documentation

template<class Type>
Block< Type >::Block ( int  size,
void(*)(char *)  err_function = NULL 
) [inline]

Definition at line 106 of file block.h.

00106 { first = last = NULL; block_size = size; error_function = err_function; }

template<class Type>
Block< Type >::~Block (  )  [inline]

Definition at line 109 of file block.h.

00109 { while (first) { block *next = first -> next; delete first; first = next; } }


Member Function Documentation

template<class Type>
Type* Block< Type >::New ( int  num = 1  )  [inline]

Definition at line 114 of file block.h.

00115         {
00116                 Type *t;
00117 
00118                 if (!last || last->current + num > last->last)
00119                 {
00120                         if (last && last->next) last = last -> next;
00121                         else
00122                         {
00123                                 block *next = (block *) new char [sizeof(block) + (block_size-1)*sizeof(Type)];
00124                                 if (!next) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }
00125                                 if (last) last -> next = next;
00126                                 else first = next;
00127                                 last = next;
00128                                 last -> current = & ( last -> data[0] );
00129                                 last -> last = last -> current + block_size;
00130                                 last -> next = NULL;
00131                         }
00132                 }
00133 
00134                 t = last -> current;
00135                 last -> current += num;
00136                 return t;
00137         }

template<class Type>
void Block< Type >::Reset (  )  [inline]

Definition at line 165 of file block.h.

00166         {
00167                 block *b;
00168                 if (!first) return;
00169                 for (b=first; ; b=b->next)
00170                 {
00171                         b -> current = & ( b -> data[0] );
00172                         if (b == last) break;
00173                 }
00174                 last = first;
00175         }

template<class Type>
Type* Block< Type >::ScanFirst (  )  [inline]

Definition at line 140 of file block.h.

00141         {
00142                 for (scan_current_block=first; scan_current_block; scan_current_block = scan_current_block->next)
00143                 {
00144                         scan_current_data = & ( scan_current_block -> data[0] );
00145                         if (scan_current_data < scan_current_block -> current) return scan_current_data ++;
00146                 }
00147                 return NULL;
00148         }

template<class Type>
Type* Block< Type >::ScanNext (  )  [inline]

Definition at line 153 of file block.h.

00154         {
00155                 while (scan_current_data >= scan_current_block -> current)
00156                 {
00157                         scan_current_block = scan_current_block -> next;
00158                         if (!scan_current_block) return NULL;
00159                         scan_current_data = & ( scan_current_block -> data[0] );
00160                 }
00161                 return scan_current_data ++;
00162         }


Member Data Documentation

template<class Type>
int Block< Type >::block_size [private]

Definition at line 188 of file block.h.

template<class Type>
void(* Block< Type >::error_function)(char *) [private]

template<class Type>
block* Block< Type >::first [private]

Definition at line 189 of file block.h.

template<class Type>
block* Block< Type >::last [private]

Definition at line 190 of file block.h.

template<class Type>
block* Block< Type >::scan_current_block [private]

Definition at line 192 of file block.h.

template<class Type>
Type* Block< Type >::scan_current_data [private]

Definition at line 193 of file block.h.


The documentation for this class was generated from the following file:
Generated on Sun Oct 26 18:22:20 2008 for maxflow-v3.0 by  doxygen 1.4.7